package com.onlinevideo.filter;

import cn.hutool.core.codec.Base64;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 将加密过后的某些地址解码,同名存储在request的Attribute里
 */
public class DeCodeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        String url = request.getParameter("url");
        url = new String( Base64.decode(url));
        request.setAttribute("url",url);
    }

    @Override
    public void destroy() {

    }
}
